package com.jweb.framework.security.crypto.cipher.asymmetric;

import java.io.ObjectInputStream;
import java.security.Key;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;

/**
 * 修改人： Thomas
 * 修改内容：新增 
 * 类说明：公钥解析工厂
 */
public class PublicKeyFactoryBean implements InitializingBean, FactoryBean<Key> {
	
	private Resource location ;
	private Key key ;
	
	public void setLocation(Resource location) {
		this.location = location;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		/** 将文件中的公钥对象读出 */
		ObjectInputStream ois = new ObjectInputStream(this.location.getInputStream());
		this.key = (Key) ois.readObject();
		ois.close();
	}

	@Override
	public Key getObject() throws Exception {
		return this.key;
	}

	@Override
	public Class<?> getObjectType() {
		return Key.class;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}

}
